# 封装读取测试数据的方法
import json

from config import BASE_PATH


def read_json(filename, apiname):
    # 获取测试数据的文件路径
    filepath = BASE_PATH + "/data/" + filename + ".json"
    # 读取测试数据
    with open(filepath, "r", encoding="utf8") as f:
        # 将测试数据解析为字典类型
        data = json.load(f)
        # 获取指定接口的测试数据
    api_data = data.get(apiname)
    # 定义一个新的列表
    data_list = []

    # 列表嵌套字典的测试数据转化为列表嵌套元组
    for a in api_data:
        data_list.append(tuple(a.values()))

        # 返回最新格式的测试数据
    return data_list


if __name__ == '__main__':
    print(read_json("test_data", "api1_data"))
    print(read_json("test_data", "api2_data"))
    print(read_json("test_data", "api3_data"))
    print(read_json("test_data", "api4_data"))
